<?php

use yii\db\Migration;

class m170517_082925_create_orders_coupons_history extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }


    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->createTable('{{%orders_coupons_history}}',[
                'id' => $this->primaryKey()->notNull().' COMMENT \'自增id\'',
                'orders_id' => $this->integer()->defaultValue(0).' COMMENT \'订单 id\'',
                'coupons_id' => $this->integer()->defaultValue(0).' COMMENT \'优惠券id\'',
                'customer_coupons_id' => $this->integer()->defaultValue(0).' COMMENT \'会员领取券id\'',
                'amount' => $this->decimal(10,2)->defaultValue(0.00).' COMMENT \'券抵用金额\'',
                'create_at' => $this->integer()->defaultValue(0) .' COMMENT \'添加时间\''
            ]);
        }
    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach($dbs as $v){
            $this->db = $v;
            $this->dropTable('{{%orders_coupons_history}}');
        }
    }

}
